//
//  M_OrderCell.swift
//  letuofu
//
//  Created by WH-JS on 2019/12/31.
//  Copyright © 2019 WH-JS. All rights reserved.
//

import UIKit

class M_OrderCell: UITableViewCell {
    let jdLab = UILabel()
    let productImg = UIImageView()
    let productNo = UILabel()
    let priceImg = UIImageView()
    let titleLab = UILabel()
    let priceLab = UILabel()
    let unitLab = UILabel()
    let NumLab = UILabel()
    var celldata : [String : Any?]? {
        didSet{
            loadData()
        }
    }
    var zoonCode :String?

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = .none
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI() {
        self.backgroundColor = .white
        let bgView = drawView() { (make) in
            make.top.equalToSuperview().offset(10)
            make.left.equalToSuperview().offset(10)
            make.width.equalTo(100)
            make.height.equalTo(100)
        }
        // 设置边框
        bgView.layer.borderWidth = 0.5
        bgView.layer.borderColor = UIColor.x999999.cgColor
        bgView.layer.cornerRadius = 5
        bgView.clipsToBounds = true
        
        bgView.drawImage(imageView: productImg,named: nil) { (make) in
            make.width.equalToSuperview()
            make.height.equalToSuperview()
            make.center.equalToSuperview()
        }
        productImg.contentMode = .scaleAspectFit
        
        bgView.drawLabel(label: jdLab,text: "京东配送", fontSize: 9, textColor: .white) { (make) in
            make.top.equalToSuperview()
            make.right.equalToSuperview()
            make.height.equalTo(12)
            make.width.equalTo(40)
        }
        jdLab.font = .boldSystemFont(ofSize: 9)
        jdLab.backgroundColor = .xFC4C02
        jdLab.textAlignment = .center
        
        drawLabel(label: titleLab, text: "", fontSize: 12, fontWeight: .regular, textColor: .x333333) { (make) in
            make.left.equalTo(bgView.snp.right).offset(10)
            make.right.equalToSuperview().offset(-10)
            make.top.equalToSuperview().offset(10)
        }
        titleLab.numberOfLines = 3
        
        drawLabel(label: productNo, text: productNo.text, fontSize: 12, fontWeight: .regular, textColor: .x999999) { (make) in
            make.left.equalTo(bgView.snp.right).offset(10)
            make.right.equalToSuperview().offset(-10)
            make.top.equalTo(titleLab.snp_bottom).offset(10)
        }
        drawLabel(label: priceLab, text: "", fontSize: 18, fontWeight: .regular, textColor: .xFC4C02) { (make) in
            make.left.equalTo(bgView.snp.right).offset(10)
            make.bottom.equalToSuperview().offset(-10)
        }
        
        drawLabel(label: unitLab, text: unitLab.text, fontSize: 11, fontWeight: .regular, textColor: .x999999) { (make) in
            make.left.equalTo(priceLab.snp.right).offset(10)
            make.bottom.equalToSuperview().offset(-12)
        }
        
        drawLabel(label: NumLab, text: "x1", fontSize: 11, fontWeight: .regular, textColor: .x999999) { (make) in
            make.right.equalToSuperview().offset(-10)
            make.bottom.equalToSuperview().offset(-12)
        }
    }
    
    func loadData() {
        if var urlstring = celldata?.getString("listPicURL") {
            if zoonCode == nil {
                zoonCode = celldata?.getString("zoneCode")
            }
            if zoonCode == "105002" {
                urlstring = (JDIMG_HOST_URL+urlstring).addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!
                jdLab.isHidden = false
            }
            else {
                urlstring = (IMG_HOST_URL+urlstring).addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!
                jdLab.isHidden = true
            }
            let url = URL(string: urlstring)
            productImg.sd_setImage(with:url)
        }
        else if let imgListData = celldata?.getDictList("imgList"),imgListData.count > 0 {
            var urlstring = imgListData[0].getString("imgUrl") ?? ""
            if zoonCode == nil {
                zoonCode = celldata?.getString("zoneCode")
            }
            if zoonCode == "105002" {
                urlstring = (JDIMG_HOST_URL+urlstring).addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!
                jdLab.isHidden = false
            }
            else {
                urlstring = (IMG_HOST_URL+urlstring).addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!
                jdLab.isHidden = true
            }
            let url = URL(string: urlstring)
            productImg.sd_setImage(with:url)
        }
        else{
            productImg.image = nil
        }
        if showProductNo {
            productNo.text = "商品编号:" + (celldata?.getString("productNo") ?? "")
        }else{
            productNo.isHidden = true
        }
        titleLab.text = celldata?.getString("productName")
        priceLab.text = anyToString(celldata?["employeeCentPrice"] as Any?) ?? anyToString(celldata?["productPrice"] as Any?)
        priceLab.text = priceLab.text?.quXiaoShuDianHouDeLing
        let dl = LocalStorage.getDic(forKey: DEFULT_MALL)
        let centUnitName = dl?.getString("centName")
        unitLab.text = celldata?.getString("centUnitName") ?? centUnitName ?? ""
        NumLab.text = "x" + (anyToString(celldata?.getInt("productNum")) ?? "1")
    }
    
    var showProductNo : Bool { return true}
}


class M_OrderFootView : UIView {
    
    let priceLab = UILabel()
    let sendPriceLab = UILabel()
    let remark = TextViewWithPlaceHolder()
    let pudNum = UILabel()
    
    override func draw(_ rect: CGRect) {
        DispatchQueue.main.asyncAfter(deadline: .now()) {
            self.setupUI()
        }
    }
    
    func setupUI() {
        let dl = LocalStorage.getDic(forKey: DEFULT_MALL)
        let centUnitName = dl?.getString("centName")
        self.backgroundColor = .white
        drawLabel(text: "商品积分", fontSize: 12, textColor: .x333333) { (make) in
            make.top.equalToSuperview().offset(20)
            make.left.equalToSuperview().offset(10)
        }
        var unitlab = drawLabel(text: centUnitName, fontSize: 12, textColor: .x999999) { (make) in
            make.top.equalToSuperview().offset(20)
            make.right.equalToSuperview().offset(-10)
        }
        drawLabel(label: priceLab, text: priceLab.text, fontSize: 12, fontWeight: .regular, textColor: .x333333) { (make) in
            make.top.equalToSuperview().offset(20)
            make.right.equalTo(unitlab.snp.left).offset(-10)
        }
        
        //画横线
        var line = drawView { (make) in
            make.left.equalToSuperview().offset(20)
            make.right.equalToSuperview().offset(-10)
            make.top.equalTo(priceLab.snp.bottom).offset(19)
            make.height.equalTo(1)
        }
        line.backgroundColor = .xF2F2F2
        
        drawLabel(text: "运费", fontSize: 12, textColor: .x333333) { (make) in
            make.top.equalTo(line.snp.bottom).offset(20)
            make.left.equalToSuperview().offset(10)
        }
        unitlab = drawLabel(text: centUnitName, fontSize: 12, textColor: .x999999) { (make) in
            make.top.equalTo(line.snp.bottom).offset(20)
            make.right.equalToSuperview().offset(-10)
        }
        drawLabel(label: sendPriceLab, text: sendPriceLab.text, fontSize: 12, fontWeight: .regular, textColor: .x333333) { (make) in
            make.top.equalTo(line.snp.bottom).offset(20)
            make.right.equalTo(unitlab.snp.left).offset(-10)
        }
        
        //画横线
        line = drawView { (make) in
            make.left.equalToSuperview().offset(20)
            make.right.equalToSuperview().offset(-10)
            make.top.equalTo(sendPriceLab.snp.bottom).offset(19)
            make.height.equalTo(1)
        }
        line.backgroundColor = .xF2F2F2
        
        let lab = drawLabel(text: "留言", fontSize: 12, textColor: .x333333) { (make) in
//            make.top.equalTo(line.snp.bottom).offset(20)
            make.left.equalToSuperview().offset(10)
        }
//        drawTextField(textField: remark, placeholder: "选填，可填写对本次交易的需求说明", fontSize: 12, fontWeight: .regular, keyboardType: .default, returnKeyType: .done) { (make) in
//            make.top.equalTo(line.snp.bottom).offset(20)
//            make.left.equalTo(lab.snp.right).offset(10)
//            make.right.equalToSuperview().offset(-10)
//        }
//        remark.textAlignment = .right
        self.addSubview(remark)
        remark.snp.makeConstraints { (make) in
            make.top.equalTo(line.snp.bottom).offset(20)
            make.left.equalTo(lab.snp.right).offset(10)
            make.right.equalToSuperview().offset(-15)
            make.height.equalTo(40)
            make.centerY.equalTo(lab)
        }
        remark.font = UIFont.systemFont(ofSize: 12)
        remark.textAlignment = .right
//        self.drawLabel(label: nil, text: "选填，可填写对本次交易的需求说明", fontSize: 12,  textColor: .x999999) { (make) in
//        }
        remark.setPlaceHolder(text: "选填，可填写对本次交易的需求说明", fontSize: 12, textColor: .x999999) { (make) in
            make.centerY.equalTo(remark)
            make.right.equalTo(self).offset(-15)
        }
//        remark.debugColor()
//        remark.backgroundColor = .clear
        
        //画横线
        line = drawView { (make) in
            make.left.equalToSuperview().offset(20)
            make.right.equalToSuperview().offset(-10)
            make.top.equalTo(remark.snp.bottom).offset(19)
            make.height.equalTo(1)
        }
        line.backgroundColor = .xF2F2F2
        
        unitlab = drawLabel(text: centUnitName, fontSize: 12, textColor: .x999999) { (make) in
            make.top.equalTo(line.snp.bottom).offset(20)
            make.right.equalToSuperview().offset(-10)
        }
        
        drawLabel(label: pudNum, text: pudNum.text, fontSize: 12, fontWeight: .regular, textColor: .x333333) { (make) in
            make.top.equalTo(line.snp.bottom).offset(20)
            make.right.equalTo(unitlab.snp.left).offset(-10)
        }
        
//        drawLabel(label: sendPriceLab, text: "共1件商品  小计 111.00", fontSize: 12, fontWeight: .regular, textColor: .x333333) { (make) in
//            make.top.equalTo(sendPriceLab.snp.bottom).offset(20)
//            make.right.equalTo(unitlab.snp.left).offset(-10)
//        }
    }
}

class M_OrderDetailFootView : UIView {
    let yunfeiLab = UILabel()
    let priceLab = UILabel()
    let sumLab = UILabel()
    let timeLab = UILabel()
    let codeLab = UILabel()
    let lyLab = UILabel()
    var orderData = [String:Any?]() {
        didSet {
            loadData()
        }
    }
    
    func loadData() {
        let freight = anyToDouble(orderData["freight"] as Any?) ?? 0.0
        let consumeCents = anyToDouble(orderData["consumeCents"] as Any?) ?? 0.0
        yunfeiLab.text = anyToString(freight)?.quXiaoShuDianHouDeLing
        priceLab.text = anyToString(consumeCents-freight)?.quXiaoShuDianHouDeLing
        sumLab.text = anyToString(consumeCents)?.quXiaoShuDianHouDeLing
        timeLab.text = anyToString(orderData["orderDate"] ?? "")
        codeLab.text = anyToString(orderData["orderID"] ?? "")
        lyLab.text = anyToString(orderData["remark"] ?? "")

        setupUI()
    }
    
    func setupUI() {
        //结算部分
        let centUnitName = orderData.getString("orderCentUnitName") ?? ""
        var bgview = drawView() { (make) in
            make.left.right.top.equalToSuperview()
            make.height.equalTo(153)
        }
        bgview.backgroundColor = .white
        
        //画横线
        var line = bgview.drawView { (make) in
            make.left.equalToSuperview().offset(10)
            make.right.equalToSuperview().offset(-10)
            make.top.equalToSuperview()
            make.height.equalTo(1)
        }
        line.backgroundColor = .xF2F2F2
        var lab = bgview.drawLabel(text: "小计", fontSize: 12, textColor: .x666666) { (make) in
            make.left.equalToSuperview().offset(10)
            make.top.equalToSuperview().offset(19)
        }
        lab = bgview.drawLabel(text: centUnitName, fontSize: 12, textColor: .x666666) { (make) in
            make.centerY.equalTo(lab)
            make.right.equalToSuperview().offset(-10)
        }
        bgview.drawLabel(label: priceLab,text: priceLab.text, fontSize: 13, textColor: .x333333) { (make) in
            make.centerY.equalTo(lab)
            make.right.equalTo(lab.snp.left).offset(-10)
        }
        
        //画横线
        line = bgview.drawView { (make) in
            make.left.equalToSuperview().offset(10)
            make.right.equalToSuperview().offset(-10)
            make.top.equalTo(priceLab.snp.bottom).offset(13)
            make.height.equalTo(1)
        }
        line.backgroundColor = .xF2F2F2
        
        lab = bgview.drawLabel(text: "运费", fontSize: 12, textColor: .x666666) { (make) in
            make.left.equalToSuperview().offset(10)
            make.top.equalToSuperview().offset(71)
        }
        lab = bgview.drawLabel(text: centUnitName, fontSize: 12, textColor: .x666666) { (make) in
            make.centerY.equalTo(lab)
            make.right.equalToSuperview().offset(-10)
        }
        bgview.drawLabel(label: yunfeiLab,text: yunfeiLab.text, fontSize: 13, textColor: .x333333) { (make) in
            make.centerY.equalTo(lab)
            make.right.equalTo(lab.snp.left).offset(-10)
        }
        
        //画横线
        line = bgview.drawView { (make) in
            make.left.equalToSuperview().offset(10)
            make.right.equalToSuperview().offset(-10)
            make.top.equalTo(yunfeiLab.snp.bottom).offset(13)
            make.height.equalTo(1)
        }
        line.backgroundColor = .xF2F2F2
        
        lab = bgview.drawLabel(text: "合计", fontSize: 12, textColor: .x666666) { (make) in
            make.left.equalToSuperview().offset(10)
            make.top.equalToSuperview().offset(123)
        }
        lab = bgview.drawLabel(text: centUnitName, fontSize: 12, textColor: .x666666) { (make) in
            make.centerY.equalTo(lab)
            make.right.equalToSuperview().offset(-10)
        }
        bgview.drawLabel(label: sumLab,text: sumLab.text, fontSize: 18, textColor: .orange) { (make) in
            make.centerY.equalTo(lab)
            make.right.equalTo(lab.snp.left).offset(-10)
        }
        
        //订单部分
        bgview = drawView() { (make) in
            make.top.equalTo(bgview.snp.bottom).offset(10)
            make.left.right.equalToSuperview()
            make.height.equalTo(145)
        }
        bgview.backgroundColor = .white
        //画横线
        line = bgview.drawView { (make) in
            make.left.equalToSuperview().offset(10)
            make.top.equalToSuperview().offset(20)
            make.width.equalTo(1)
            make.height.equalTo(10)
        }
        line.backgroundColor = .red
        lab = bgview.drawLabel(text: "订单信息", fontSize: 12, textColor: .x666666) { (make) in
            make.left.equalTo(line).offset(4)
            make.centerY.equalTo(line)
        }
        
        lab = bgview.drawLabel(text: "兑换时间", fontSize: 12, textColor: .x666666) { (make) in
            make.left.equalToSuperview().offset(10)
            make.top.equalToSuperview().offset(50)
        }
        bgview.drawLabel(label: timeLab,text: timeLab.text, fontSize: 13, textColor: .x666666) { (make) in
            make.centerY.equalTo(lab)
            make.right.equalToSuperview().offset(-10)
        }
        
        lab = bgview.drawLabel(text: "订单号", fontSize: 12, textColor: .x666666) { (make) in
            make.left.equalToSuperview().offset(10)
            make.top.equalToSuperview().offset(82)
        }
        
        let btn = drawButton(title: "复制", titleColor: .x999999, fontSize: 12) { (make) in
            make.centerY.equalTo(lab)
            make.right.equalToSuperview().offset(-10)
            make.width.equalTo(40)
            make.height.equalTo(15)
        }
        // 设置边框
        btn.layer.borderWidth = 1
        btn.layer.borderColor = UIColor.x999999.cgColor
        btn.layer.cornerRadius = 7.5
        btn.hitEdgInsets = .init(top: -20, left: -20, bottom: -20, right: -20)
        btn.addTarget(self, action: #selector(_copybtnClick(button:)), for: .touchUpInside)
        
        bgview.drawLabel(label: codeLab,text: codeLab.text, fontSize: 13, textColor: .x666666) { (make) in
            make.centerY.equalTo(lab)
            make.right.equalTo(btn.snp.left).offset(-10)
        }
        
        lab = bgview.drawLabel(text: "留言", fontSize: 12, textColor: .x666666) { (make) in
            make.left.equalToSuperview().offset(10)
            make.top.equalToSuperview().offset(113)
        }
        bgview.drawLabel(label: lyLab,text: lyLab.text, fontSize: 13, textColor: .x666666) { (make) in
            make.centerY.equalTo(lab)
            make.right.equalToSuperview().offset(-10)
        }
        
        //客服
        bgview = drawView() { (make) in
            make.top.equalTo(bgview.snp.bottom).offset(10)
            make.left.right.equalToSuperview()
            make.height.equalTo(53)
        }
        bgview.backgroundColor = .white
        bgview.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(kefyTap(tap:))))
        bgview.isUserInteractionEnabled = true
        bgview.drawImage(image: UIImage.init(named: "order_kefu")) { (make) in
            make.centerY.equalToSuperview()
            make.centerX.equalToSuperview().offset(-25)
        }
        bgview.drawLabel(text: "联系客服", fontSize: 12, textColor: .x333333) { (make) in
            make.centerY.equalToSuperview()
            make.centerX.equalToSuperview().offset(15)
        }
    }
    
    @objc func kefyTap(tap:UITapGestureRecognizer){
        let vc = M_SimpleArticleVC()
        UIViewController.topMostController()?.pushViewController(vc)
        let qidiandic = LocalStorage.getDic(forKey: QIDIAN_KEY)
        vc.loadUrl(qidiandic?.getString("id") ?? "https://url.cn/50hfdES?_type=wpa&qidian=true")

        vc.headTitle.text = "联系客服"
    }
    
    @objc func _copybtnClick(button: Button) {
        let pastboard = UIPasteboard.general
        pastboard.string = (orderData.getString("orderID") ?? "")

        let popup = PopupBox(infoText: "已复制")
        if let vc = UIViewController.topMostController() {
            popup.show(vc: vc)
        }
    }
}

class M_OrderListFootView : UIView {
    //定义一个闭包类型(购买类型回调)
    typealias payBlock = (_ data: [String:Any?]) -> Void
    //声明一个变量
    var payBack: payBlock?
    //定义一个方法,方法的参数为和swiftBlock类型一致的闭包,并赋值给callBack
    func callPayBlock(block: @escaping payBlock) {
        payBack = block
    }
    
    //定义一个闭包类型(取消回调)
    typealias cancelBlock = (_ data: [String:Any?]) -> Void
    //声明一个变量
    var cancelBack: cancelBlock?
    //定义一个方法,方法的参数为和swiftBlock类型一致的闭包,并赋值给callBack
    func callCancelBlock(block: @escaping cancelBlock) {
        cancelBack = block
    }
    
    //定义一个闭包类型(取消回调)
    typealias seeBlock = (_ data: [String:Any?]) -> Void
    //声明一个变量
    var seeBack: seeBlock?
    //定义一个方法,方法的参数为和swiftBlock类型一致的闭包,并赋值给callBack
    func callSeeBlock(block: @escaping seeBlock) {
        seeBack = block
    }
    
    //定义一个闭包类型(取消回调)
    typealias signBlock = (_ data: [String:Any?]) -> Void
    //声明一个变量
    var signBack: signBlock?
    //定义一个方法,方法的参数为和swiftBlock类型一致的闭包,并赋值给callBack
    func callSignBlock(block: @escaping signBlock) {
        signBack = block
    }
    
    var isold = false
    let orderCodeLab = UILabel()
    let timeLab = UILabel()
    let priceLab = UILabel()
    let centUnitNameLab = UILabel()
    let remark = TextField()
    let pudNum = UILabel()
    let paybtn = Button()
    let seebtn = Button()
    let cancelbtn = Button()
    let signbtn = Button()
    var orderData = [String:Any?]() {
        didSet {
            pudNum.text = "共" + (anyToString(orderData.getInt("productTotal")) ?? "0") + "件商品  (含运费"
            pudNum.text! += (orderData.getString("freight") ?? "0") + "积分)"
            orderCodeLab.text = "订单号:" + (orderData.getString("orderID") ?? "")
            priceLab.text = anyToString((anyToDouble(orderData["consumeCents"] ?? 0.0) ?? 0.0))
            priceLab.text = priceLab.text?.quXiaoShuDianHouDeLing
            timeLab.text = orderData.getString("orderDate")
            centUnitNameLab.text = orderData.getString("centUnitName")
            
            if !self.isold {
                self.setupUI()
            }
        }
    }
    
    override func draw(_ rect: CGRect) {
    }
    
    func setupUI() {
        isold = true
        self.backgroundColor = .white
        
        drawLabel(label: orderCodeLab, text: orderCodeLab.text, fontSize: 12, fontWeight: .regular, textColor: .x999999) { (make) in
            make.top.equalToSuperview().offset(20-14+1)
            make.left.equalToSuperview().offset(10)
        }
        
        let btn = drawButton(title: "复制", titleColor: .x999999, fontSize: 12) { (make) in
            make.left.equalTo(orderCodeLab.snp.right).offset(7)
//            make.top.equalToSuperview().offset(20)
            make.width.equalTo(40)
//            make.height.equalTo(15)
            make.centerY.equalTo(orderCodeLab)
        }
        // 设置边框
        btn.layer.borderWidth = 1
        btn.layer.borderColor = UIColor.x999999.cgColor
        btn.layer.cornerRadius = 7.5
        btn.hitEdgInsets = .init(top: -20, left: -20, bottom: -20, right: -20)
        btn.addTarget(self, action: #selector(_copybtnClick(button:)), for: .touchUpInside)
        
        drawLabel(label: timeLab, text: timeLab.text, fontSize: 12, fontWeight: .regular, textColor: .x999999) { (make) in
//            make.top.equalToSuperview().offset(20)
            make.centerY.equalTo(orderCodeLab)
            make.right.equalToSuperview().offset(-10)
        }
        
        //画横线
        var line = drawView { (make) in
            make.left.equalToSuperview().offset(10)
            make.right.equalToSuperview().offset(-10)
            make.top.equalTo(timeLab.snp.bottom).offset(20-1)
            make.height.equalTo(0.5)
        }
        line.backgroundColor = .xF2F2F2
        
        drawLabel(label: pudNum, text: pudNum.text, fontSize: 12, fontWeight: .regular, textColor: .x333333) { (make) in
            make.top.equalTo(line.snp.bottom).offset(20)
            make.right.equalToSuperview().offset(-10)
        }
        
        drawLabel(label: centUnitNameLab,text: centUnitNameLab.text, fontSize: 11, textColor: .x999999) { (make) in
            make.top.equalTo(pudNum.snp.bottom).offset(22)
            make.right.equalToSuperview().offset(-10)
        }
        
        drawLabel(label: priceLab, text: priceLab.text, fontSize: 18, fontWeight: .regular, textColor: .xFC4C02) { (make) in
            make.bottom.equalTo(centUnitNameLab).offset(2)
            make.right.equalTo(centUnitNameLab.snp.left).offset(-6)
        }
        
        let amountLabel = drawLabel(text: "合计：", fontSize: 11, textColor: .x333333) { (make) in
            make.bottom.equalTo(centUnitNameLab)
            make.right.equalTo(priceLab.snp.left).offset(-7+4)
        }
        
        //待支付
        if orderData.getString("orderProcessStateCode") == "104001"  {
            drawButton(button: paybtn,title: "立即支付", titleColor: .xFC4C02, fontSize: 12) { (make) in
                make.width.equalTo(68.5)
                make.height.equalTo(26)
                make.top.equalTo(amountLabel.snp.bottom).offset(20)
                make.right.equalToSuperview().offset(-10)
            }
            // 设置边框
            paybtn.layer.borderWidth = 0.5
            paybtn.layer.borderColor = UIColor.xFC4C02.cgColor
            paybtn.layer.cornerRadius = 13
            paybtn.addTarget(self, action: #selector(_paybtnClick(button:)), for: .touchUpInside)
            
            
//            if orderData.getString("zoneCode") == "105001"  {
                drawButton(button: cancelbtn,title: "取消订单", titleColor: .x999999, fontSize: 12) { (make) in
                    make.width.equalTo(68.5)
                    make.height.equalTo(26)
//                    make.top.equalTo(priceLab.snp.bottom).offset(20)
                    make.centerY.equalTo(paybtn)
                    make.right.equalTo(paybtn.snp.left).offset(-10)
                }
                // 设置边框
                cancelbtn.layer.borderWidth = 0.5
                cancelbtn.layer.borderColor = UIColor.x999999.cgColor
                cancelbtn.layer.cornerRadius = 13
                cancelbtn.addTarget(self, action: #selector(_cancelbtnClick(button:)), for: .touchUpInside)
//            }
//
//            //画横线
//            line = drawView { (make) in
//                make.left.right.equalToSuperview()
//                make.top.equalTo(paybtn.snp.bottom).offset(20)
//                make.height.equalTo(10)
//            }
//            line.backgroundColor = .red
        }
            //待发货
        else if orderData.getString("orderProcessStateCode") == "104002" {
            
//            if orderData.getString("zoneCode") == "105001"  {
//                drawButton(button: cancelbtn,title: "取消订单", titleColor: .x999999, fontSize: 12) { (make) in
//                    make.width.equalTo(68.5)
//                    make.height.equalTo(26)
//                    make.top.equalTo(priceLab.snp.bottom).offset(20)
//                    make.right.equalToSuperview().offset(-10)
//                }
//                // 设置边框
//                cancelbtn.layer.borderWidth = 0.5
//                cancelbtn.layer.borderColor = UIColor.x999999.cgColor
//                cancelbtn.layer.cornerRadius = 13
//                cancelbtn.addTarget(self, action: #selector(_cancelbtnClick(button:)), for: .touchUpInside)
//
//                //画横线
//                line = drawView { (make) in
//                    make.left.right.equalToSuperview()
//                    make.bottom.equalToSuperview()
//                    make.height.equalTo(10)
//                }
//                line.backgroundColor = .red
////            }
            
        }
            //待收货
        else if orderData.getString("orderProcessStateCode") == "104003" {
            drawButton(button: signbtn,title: "确认收货", titleColor: .xFC4C02, fontSize: 12) { (make) in
                make.width.equalTo(68.5)
                make.height.equalTo(26)
                make.top.equalTo(priceLab.snp.bottom).offset(20)
                make.right.equalToSuperview().offset(-10)
            }
            // 设置边框
            signbtn.layer.borderWidth = 0.5
            signbtn.layer.borderColor = UIColor.xFC4C02.cgColor
            signbtn.layer.cornerRadius = 13
            signbtn.addTarget(self, action: #selector(_signbtnClick(button:)), for: .touchUpInside)
            
            drawButton(button: seebtn,title: "查看物流", titleColor: .x999999, fontSize: 12) { (make) in
                make.width.equalTo(68.5)
                make.height.equalTo(26)
                make.top.equalTo(amountLabel.snp.bottom).offset(20)
                make.right.equalTo(signbtn.snp.left).offset(-10)
            }
            // 设置边框
            seebtn.layer.borderWidth = 0.5
            seebtn.layer.borderColor = UIColor.x999999.cgColor
            seebtn.layer.cornerRadius = 13
            seebtn.addTarget(self, action: #selector(_seebtnClick(button:)), for: .touchUpInside)
            
//            //画横线
//            line = drawView { (make) in
//                make.left.right.equalToSuperview()
//                make.top.equalTo(seebtn.snp.bottom).offset(20)
//                make.height.equalTo(10)
//            }
//            line.backgroundColor = .red
        }
            //订单取消
        else if orderData.getString("orderProcessStateCode") == "104005" {
//            //画横线
//            line = drawView { (make) in
//                make.left.right.bottom.equalToSuperview()
//                make.top.equalTo(priceLab.snp.bottom).offset(40)
//            }
//            line.backgroundColor = .red
        }
        //已确认收货
        else if orderData.getString("orderProcessStateCode") == "104004" {
            drawButton(button: seebtn,title: "查看物流", titleColor: .x999999, fontSize: 12) { (make) in
                make.width.equalTo(68.5)
                make.height.equalTo(26)
                make.top.equalTo(amountLabel.snp.bottom).offset(20)
                make.right.equalToSuperview().offset(-10)
            }
            // 设置边框
            seebtn.layer.borderWidth = 0.5
            seebtn.layer.borderColor = UIColor.x999999.cgColor
            seebtn.layer.cornerRadius = 13
            seebtn.addTarget(self, action: #selector(_seebtnClick(button:)), for: .touchUpInside)
            
//            //画横线
//            line = drawView { (make) in
//                make.left.right.equalToSuperview()
//                make.top.equalTo(seebtn.snp.bottom).offset(20)
//                make.height.equalTo(10)
//            }
//            line.backgroundColor = .red
        }
        
        
        //画横线
        line = drawView { (make) in
            make.left.right.equalToSuperview()
            make.bottom.equalToSuperview()
            make.height.equalTo(10)
        }
        line.backgroundColor = .xF2F2F2
    }
    

    
    @objc func _copybtnClick(button: Button) {
        let pastboard = UIPasteboard.general
        pastboard.string = (orderData.getString("orderID") ?? "")

        let popup = PopupBox(infoText: "已复制")
        if let vc = UIViewController.topMostController() {
            popup.show(vc: vc)
        }
    }
    
    @objc func _signbtnClick(button: Button) {
        if signBack != nil {
            signBack!(orderData)
        }
    }
    
    @objc func _seebtnClick(button: Button) {
        if seeBack != nil {
            seeBack!(orderData)
        }
    }
    
    @objc func _cancelbtnClick(button: Button) {
        if cancelBack != nil {
            cancelBack!(orderData)
        }
    }
    
    @objc func _paybtnClick(button: Button) {
        if payBack != nil {
            payBack!(orderData)
        }
    }
}
